package com.seal.pay.account.service.impl;

import com.seal.commons.copiers.BeanMapper;
import com.seal.pay.account.entity.AccountAdjustRecord;
import com.seal.pay.account.bo.AccountAdjustRecordBO;
import com.seal.pay.account.service.AccountAdjustRecordService;
import com.seal.pay.account.repository.AccountAdjustRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.Optional;


/**
* 功能描述: <br/>
* @date:    2020-11-23 21:32:33<br/>
* @author   yong.huang
* @since    JDK 1.8
*/
@Service
public class AccountAdjustRecordServiceImpl implements AccountAdjustRecordService {

    @Autowired
    private AccountAdjustRecordRepository accountAdjustRecordRepository;

    @Override
    public AccountAdjustRecordBO create(AccountAdjustRecordBO bo) {
        AccountAdjustRecord entity = bo.toEntity(AccountAdjustRecord.class);
        entity.setCreateDateTime(LocalDateTime.now());
        entity = accountAdjustRecordRepository.saveAndFlush(entity);
        bo.parse(entity);
        return bo;
    }

    @Override
    public AccountAdjustRecordBO getById(String id) {
        Optional<AccountAdjustRecord> optional = accountAdjustRecordRepository.findById(id);
        if(optional.isPresent()){
            return BeanMapper.cglibCopy(optional.get(), AccountAdjustRecordBO.class);
        }
        return null;
    }


}